import Vue from 'vue';
import VueRouter from 'vue-router';
import App from '../App.vue';
import inobounce from 'inobounce';

Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};
const routes = [
    {
        path: '/',
        name: 'App',
        component: App,
        redirect: '/customerDetail',
        children: [
            {
                path: '/customerDetail', // 客户详情
                name: 'customerDetail',
                component: () => import(/* webpackChunkName: "about" */ '@/views/customer-detail.vue'),
                meta: {
                    keepAlive: true,
                    title: '客户详情'
                }
            },
            {
                path: '/verbalManage', // 话术库
                name: 'verbalManage',
                component: () => import(/* webpackChunkName: "about" */ '@/views/verbal-manage.vue'),
                meta: {
                    keepAlive: true,
                    title: '话术库'
                }
            },
            {
                path: '/marketMaterial', // 营销素材
                name: 'marketMaterial',
                component: () => import(/* webpackChunkName: "about" */ '@/views/market-material.vue'),
                meta: {
                    keepAlive: true,
                    title: '营销素材'
                }
            },
            {
                path: '/managerReminder', // 经理提醒
                name: 'managerReminder',
                component: () => import(/* webpackChunkName: "about" */ '@/views/manager-reminder.vue'),
                meta: {
                    keepAlive: true,
                    title: '经理提醒'
                }
            },
            {
                path: '/financialShop', // 金融小店
                name: 'financialShop',
                component: () => import(/* webpackChunkName: "about" */ '@/views/financial-shop.vue'),
                meta: {
                    keepAlive: true,
                    title: '金融小店'
                }
            },
            {
                path: '/customerQRcode', //侧边栏-一客一码 页面
                name: 'customerQRcode',
                component: () => import(/* webpackChunkName: "about" */ '@/views/customer-qrcode.vue'),
                meta: {
                    keepAlive: true,
                    title: '一客一码'
                }
            },
            {
                path: '/managerView', // 经理视图
                name: 'managerView',
                component: () => import(/* webpackChunkName: "about" */ '@/views/manager-view.vue'),
                meta: {
                    keepAlive: true,
                    title: '经理视图'
                }
            },
            // 客户详情下的子页面
            {
                path: '/customerDetail/member-list',
                name: 'member-list',
                component: () => import(/* webpackChunkName: "views" */ '@/views/customer-detail/member-list'),
                meta: {
                    keepAlive: true,
                    title: '员工及群聊列表'
                }
            },
            {
                path: '/customerDetail/crm-customer-detail',
                name: 'crm-customer-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/customer-detail/crm-customer-detail'),
                meta: {
                    keepAlive: true,
                    title: 'CRM信息'
                }
            },
            {
                path: '/customerDetail/add-tags',
                name: 'add-tags',
                component: () => import(/* webpackChunkName: "views" */ '@/views/customer-detail/add-tags'),
                meta: {
                    keepAlive: true,
                    title: '添加标签'
                }
            },
            // 金融小店下子页面
            {
                path: '/financialShop/customer-manager-detail',
                name: 'customer-manager-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/customer-manager-detail'),
                meta: {
                    keepAlive: true,
                    title: '客户经理信息'
                }
            },
            {
                path: '/financialShop/product-list',
                name: 'product-list',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/product-list'),
                meta: {
                    keepAlive: true,
                    title: '产品列表'
                }
            },
            {
                path: '/financialShop/picture-list', // 活动 信用卡 贷款列表页(只展示图片列表)
                name: 'picture-list',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/picture-list'),
                meta: {
                    keepAlive: true,
                    title: '产品列表'
                }
            },
            {
                path: '/financialShop/picture-detail', // 活动 信用卡 贷款详情页
                name: 'picture-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/picture-detail'),
                meta: {
                    keepAlive: true,
                    title: '产品详情'
                }
            },
            {
                path: '/financialShop/financial-detail',
                name: 'financial-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-detail'),
                meta: {
                    keepAlive: true,
                    title: '理财产品详情'
                }
            },
            {
                path: '/financialShop/financial-fund-detail',
                name: 'financial-fund-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-fund-detail'),
                meta: {
                    keepAlive: true,
                    title: '基金产品详情'
                }
            },
            {
                path: '/financialShop/financial-fund-unit-detail',
                name: 'financial-fund-unit-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-fund-unit-value'),
                meta: {
                    keepAlive: true,
                    title: '基金产品单位净值'
                }
            },
            {
                path: '/financialShop/financial-happiness-deposit',
                name: 'financial-happiness-deposit',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-happiness-deposit'),
                meta: {
                    keepAlive: true,
                    title: '幸福存单'
                }
            },
            {
                path: '/financialShop/financial-saving-product',
                name: 'financial-saving-product',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-saving-product'),
                meta: {
                    keepAlive: true,
                    title: '幸福通知存'
                }
            },
            {
                path: '/financialShop/financial-deposit-taking',
                name: 'financial-deposit-taking',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-deposit-taking'),
                meta: {
                    keepAlive: true,
                    title: '整存整取'
                }
            },
            {
                path: '/financialShop/financial-call-deposit',
                name: 'financial-call-deposit',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-call-deposit'),
                meta: {
                    keepAlive: true,
                    title: '通知存款'
                }
            },
            {
                path: '/financialShop/financial-zero-deposit-taking',
                name: 'financial-zero-deposit-taking',
                component: () => import(/* webpackChunkName: "views" */ '@/views/financial/financial-zero-deposit-taking'),
                meta: {
                    keepAlive: true,
                    title: '零存整取'
                }
            },
            // 一客一码下子页面
            {
                path: '/customerQRcode/invite-list',
                name: 'invite-list',
                component: () => import(/* webpackChunkName: "views" */ '@/views/customer-qrcode/invite-list'),
                meta: {
                    keepAlive: true,
                    title: '邀请列表'
                }
            },
            // 经理视图下的子页面
            {
                path: '/managerView/remind-page',
                name: 'remind-page',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/remind-page'),
                meta: {
                    keepAlive: true,
                    title: '提醒' // 产品到期 生日提醒 活期余额提醒
                }
            },
            {
                path: '/managerView/remind-customer',
                name: 'remind-customer',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/remind-customer'),
                meta: {
                    keepAlive: true,
                    title: '未交流客户提醒'
                }
            },
            {
                path: '/managerView/marketing-thread',
                name: 'marketing-thread',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/marketing-thread'),
                meta: {
                    keepAlive: true,
                    title: '营销线索'
                }
            },
            {
                path: '/managerView/marketing-detail',
                name: 'marketing-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/marketing-detail'),
                meta: {
                    keepAlive: true,
                    title: '线索详情'
                }
            },
            {
                path: '/managerView/customer-radar',
                name: 'customer-radar',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/customer-radar'),
                meta: {
                    keepAlive: true,
                    title: '客户雷达'
                }
            },
            {
                path: '/managerView/data-board',
                name: 'data-board',
                component: () => import(/* webpackChunkName: "views" */ '@/views/manager-view/data-board'),
                meta: {
                    keepAlive: true,
                    title: '数据看板'
                }
            },
            {
                path: '/managerView/red-packet',
                name: 'red-packet',
                component: () => import(/* webpackChunkName: "views" */ '@/components/manager-view/red-packet'),
                meta: {
                    title: '红包首页'
                }
            },
            {
                path: '/managerView/red-packet-detail',
                name: 'red-packet-detail',
                component: () => import(/* webpackChunkName: "views" */ '@/components/manager-view/red-packet-detail'),
                meta: {
                    title: '红包详情页'
                }
            },
            {
                path: '/managerView/red-packet-cash',
                name: 'red-packet-cash',
                component: () => import(/* webpackChunkName: "views" */ '@/components/manager-view/red-packet-cash'),
                meta: {
                    title: '红包提现页'
                }
            },
            // 公共子页面
            {
                path: '/public-page/external-link',
                name: 'external-link',
                component: () => import(/* webpackChunkName: "views" */ '@/views/public-page/external-link'),
                meta: {
                    keepAlive: true,
                    title: '外链'
                }
            },
            {
                path: '/public-page/down-app-page',
                name: 'down-app-page',
                component: () => import(/* webpackChunkName: "views" */ '@/views/public-page/down-app-page'),
                meta: {
                    keepAlive: true,
                    title: '打开/下载app'
                }
            },
            {
                path: '/uploadFile',
                name: 'uploadFile',
                component: () => import(/* webpackChunkName: "views" */ '@/views/public-page/upload-file'),
                meta: {
                    keepAlive: true,
                    title: '上传文件'
                }
            },
            {
                path: '/404', //找不到页面
                component: () => import(/* webpackChunkName: "about" */ '@/components/error-page/not-found'),
                name: '404'
            },
            {
                path: '/financialShop/paper/index', // 活动 信用卡 贷款详情页
                name: 'paper-index',
                component: () => import(/* webpackChunkName: "views" */ '@/views/paper/index'),
                meta: {
                    keepAlive: true,
                    title: '早报首页'
                }
            },
            {
                path: '/financialShop/paper/list',
                name: '早报列表',
                component: () => import(/* webpackChunkName: "page" */ '@/views/paper/list'),
                meta: {
                    keepAlive: true,
                    title: '早报列表页'
                }
            },
            {
                path: '/financialShop/paper/detail',
                name: '早报详情',
                component: () => import(/* webpackChunkName: "page" */ '@/views/paper/detail'),
                meta: {
                    title: '早报详情页'
                }
            }
        ]
    }
];

const router = new VueRouter({
    mode: 'hash',
    routes
});

router.beforeEach((to, from, next) => {
    document.title = to.meta.title;
    let u = navigator.userAgent;
    if (to.name == 'customerDetail') {
        if (u.indexOf('iPhone') > -1) {
            inobounce.disable();
        }
    } else {
        if (u.indexOf('iPhone') > -1) {
            inobounce.enable();
        }
    }
    sessionStorage.setItem('from_page_name', from.name);
    if (!to.query.wxUserId) {
        //如果目标路由没有公共参数，就获取公共参数并添加
        let wxUserId = from.query.wxUserId;
        if (wxUserId) {
            //如果公共参数不为空，则塞进目标路由中
            to.query.wxUserId = wxUserId;
            next({
                to: to.name,
                query: to.query
            });
        } else {
            next();
        }
    } else {
        next();
    }
});

export default router;
